# -*- coding: utf-8 -*-
'''
@IDE : PyCharm
@version : 3.9
@Auth : gouzi
@time : 2024/2/16 12:45
@Description:
'''
import requests
from utils import header_str_to_dict
import urllib3
 
urllib3.disable_warnings()
header_str = '''
sh-token	07YHP1RqF2ZjZiZDRlMjg0ZWJlNmY5OWRiVrVJil+FyNFpPfAYRwUnQZjD7Y0EMrH0URCKv764zx2HrJrYl7RugWdY2JZP2mlh2o63ZQhD9f2BlkbdZzS3eRaVNn+LfKaM+2xWa3yAnTwDsBJq658HFt7VNjuaBKnX+e9kjFcgtdCl2h0kIgZyFA=='''
headers = header_str_to_dict(header_str)
# 搜索商品的接口
res = requests.post(
    url="https://sh-api.shihuo.cn/daga/search/goods/v1?minVersion=15670&clientCode=%7Bholder%7D&v=7.20.1&channel=myapp&device=Pixel%202%20XL&platform=android&timestamp=1697021144536&token=3dec4554119714351dedd1f457099573",
    # headers=headers,
    json={
        "keywords": "帆布鞋",
        "pageSize": "20",
        "page": "1",
 
    }, verify=False
)
print(res.text)
data_dict = res.json()
 
print('------')
l = []
for item in data_dict['data']['lists']:
    try:
        print(item['name'])
        for ele in item['style_lists']:
            print('-----', ele['goods_id'], ele['name'], ele['price'])
            # 通过商品id，获取商品的详情
            l.append(ele['goods_id'])
    except:
        pass
 
# header_str = '''
# platform	android
# timestamp	1697022069424
# app-v	7.20.1
# sh-token	19Zo0LudYxM2M3NDBiZThjNmNjNTM1ZGMwnqndf6tomH872jLQjhgYbdFdIyqJGmWsdG6mb1tPj5mcB/3l6G58H274IwjqbjH09QyGMZg/QEqYOjTFSXdZ6SqroQY0+7KrhcoExdS0hlCpdaSb4FF9/sPivU2Eh9ZoPRaufuOMqX08wzYTIF4eug==
# sh-id	913962kpcbdb29f68fc2552232c86cb3
# sh-sign	DF380FBA1CF473B2FDD4BC570F6EB5B1
# abtest-control	ln=3;eI=3;HN=0;LR=0;Ks=0;eN=2;Gs=2;zF=1;Ta=2;uc=2;aQ=0;Xj=1;zT=0;IG=0;AA=2;Df=13;MQ=1;fK=11;data_community_personal=3;jO=2;UZ=0;fL=0;Lu=1;nY=2;am=0;EQ=2;shrec_is_gdetail=12;RA=2;ev=22;kA=3;kB=11;ay=3;gA=2;mainSearchV3=25;search_wf=3;NI=0;mainSearchV4=27;nj=2;Us=1;nn=0;zz=12;Yz=1;shrec_gdetail_bags=11;Qv=17;Ah=11;data_gdetail_shoes_personal=11;data_gdetail_clothes_personal=11;oZ=12;shoes_ratio_ctrl=0;bn=0;sa=0;Ap=2;gdetail_shoes_brand_rec=11;JZ=1;SD=0;fx=3;sf=12;Av=24;sh=0;Rg=2;cY=1;Rh=15;tK=3;shrec_home_feed=17;Fd=2;gf=12;dD=0;gh=0;CI=1;ou=3;dK=0;Fn=3;CL=2;GP=1;t_s=1697020869050;oy=2;gdetail_brand_rec=11;shrec_cf_mine_v2=11;KY=6;hW=3;Wg=12;pa=0;shrec_gdetail_clothes=11;Od=11;yN=8;By=0;Bz=0;uO=0;data_community_relate=11;dc=1
# shreqid	57F9D010EF0EA0A05E845396BA6B3E1F
# osv	11
# network	1
# sh_session	7804c48b010b40f699adcc4b4aaa89f0_foreground_1002591
# sk	9MJTD4FFJBgRUPSgNfZIKOA8bCGnv4wt7McVWcxBYyOZBJiez6r4AjzcgGweapZa1GGcamedBEXYqzEOVegB7d2klJ1w
# appid	app
# cookie	acw_tc=76b20fe616970207931503924e60da603e28e89a17d213f16b5b87b95b3433
# user-agent	Android 11 {Z29vZ2xl} CPU_ABI arm64-v8a CPU_ABI2  HARDWARE taimen MODEL {UGl4ZWwgMiBYTA} network/WIFI shihuo/7.20.1 sc({holder},myapp) minVersion(15670) sh-dv-sign[v1|6bd3e4ffa3ce6c880e6681a9f90775c60d2751f79b8da0aa]
# '''
# for good_id in l:
#     print(good_id)
#     headers = header_str_to_dict(header_str)
#     res = requests.get(
#         url=f'https://sh-gateway.shihuo.cn/v4/services/sh-goodsapi/app_swoole_shoe/preload/single?devices=Pixel%202%20XL&dspm=95e6ec308860e77a&gender=2&goods_id={good_id}&sourceLocation=oneRowOne%3A%5BN%5D&style_id=40941356&top_style_id=40941356&tpExtra=%7B%22sourceTp%22%3A%22home%3Asearch%3A%22%2C%22sourceTpName%22%3A%22%E5%B8%86%E5%B8%83%E9%9E%8B%22%2C%22wsf%22%3A%22normal_search_words%22%2C%22ast%22%3A%22%E5%B8%86%E5%B8%83%E9%9E%8B%22%2C%22is_inspire%22%3A0%2C%22dgReqId%22%3A%22SHSS_CG-O7CKNHGTO8RT_SPU_1%3A27%22%2C%22si%22%3A%228001%22%2C%22skc%22%3A%2240941356%22%2C%22layer%22%3A%222%22%7D&access_token=b7EM8Up9VSFJUhkyEJ&minVersion=15670&clientCode=%7Bholder%7D&v=7.20.1&channel=myapp&device=Pixel%202%20XL&platform=android&timestamp=1697022069424&access_token=b7EM8Up9VSFJUhkyEJ&token=570a49e713cc2b3a2a3a1e627878b86b',
#         verify=False,
#         headers=headers
#     )
#     print(res.text)
#     break
#     print('付款人数：', res.json()['data']['info']['goods_info']['monthSellPoint'])